package zju.dgm.dto;


import lombok.*;

import java.io.Serializable;
import java.util.Objects;

/**
 * 记录某个client的各种信息
 * @author lzy
 */

@Setter
@Getter
public class ServerInfo implements Serializable {


    private String name;
    private String ip;
    private int port;

    /**
     * 用于json序列化
     */
    public ServerInfo(){}

    public ServerInfo(String name, String ip, int port) {
        this.name = name;
        this.ip = ip;
        this.port = port;
    }

    public String getName() {
        return name;
    }

    public String getIp() {
        return ip;
    }

    public int getPort() {
        return port;
    }

    /**
     * 只比较 name ip 和 port
     * @param o
     * @return
     */
    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        ServerInfo that = (ServerInfo) o;
        return port == that.port && Objects.equals(name, that.name) && Objects.equals(ip, that.ip);
    }

    @Override
    public int hashCode() {
        return Objects.hash(name, ip, port);
    }

    @Override
    public String toString() {
        return "ServerInfo{" +
                "name='" + name + '\'' +
                ", ip='" + ip + '\'' +
                ", serverPort=" + (port-1) +
                '}';
    }
}


